package org.yray.serializer.kryo;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.ByteBufferInput;
import com.esotericsoftware.kryo.io.ByteBufferOutput;

public class KryoService {



    public byte[] seri(KryoVo kryoVo)
    {
        Kryo kryo = new Kryo();
        kryo.register(KryoVo.class,new KryoSerializer());
        ByteBufferOutput baos = new ByteBufferOutput(1024*10);
        kryo.writeObject(baos,kryoVo);
        byte[] kryobytes=baos.toBytes();
        baos.close();
        return kryobytes;
    }

    public KryoVo de(byte[] kryobytes)
    {
        Kryo kryo = new Kryo();
        kryo.register(KryoVo.class,new KryoSerializer());
        ByteBufferInput input=new ByteBufferInput(kryobytes);
        KryoVo kryoVo=kryo.readObject(input,KryoVo.class);
        return kryoVo;
    }
}
